<template>
  <div id="tab-control">
    <div 
      v-for="(item,index) in controls" 
      :key="item.index" 
      class="tab-control-item" 
      @click="itemclick(index)">
      <span :class="{active:index===currentindex}">{{item}}</span>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    controls: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      currentindex: 0
    };
  },
  methods: {
    itemclick(index){
      this.currentindex = index;
      this.$emit('tabclick',index)
    }
  }
};
</script>

<style scoped>
#tab-control {
  display: flex;
  text-align: center;
  height: 40px;
  line-height: 40px;
  font-size: 15px;
  font-weight: 500;
  background-color: #fff;
}

.tab-control-item {
  flex: 1;
}

.active {
  color: deeppink;
  border-bottom: 3px solid deeppink;
  padding: 4px;
}
</style>